package com.hu.hutool.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.UUID;
import com.aliyun.oss.OSS;
import com.commons.tools.utils.Result;
import com.hu.hutool.util.OssFileUploadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author CazCen
 * @Date 2022/1/16 2:30
 */
@RestController
@RequestMapping("/oss")
@Api(tags = "文件上传到oss")
@Slf4j
public class OssController {

//    https://blog.csdn.net/weixin_43118617/article/details/120311886
//    https://oss.console.aliyun.com/bucket/oss-cn-shenzhen/buket-name/object
    
    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public Result<String> uploadImg(MultipartFile file) throws IOException {

        String url = OssFileUploadUtil.upLoadFile(file);

        log.info("url:{}",url);

        return Result.ok(url);
    }

}
